import { defineConfig } from 'vite';  
import vue from '@vitejs/plugin-vue';  
import compression from 'vite-plugin-compression';  
import AutoImport from 'unplugin-auto-import/vite' 
import Components from 'unplugin-vue-components/vite' 
import { VantResolver } from '@vant/auto-import-resolver';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' 
import { resolve } from 'path';
import * as fs from 'fs';
  
export default defineConfig({  
  plugins: [  
    vue(),  
    AutoImport({ 
      resolvers: [ElementPlusResolver(),VantResolver()], 
    }), 
    Components({ 
      resolvers: [ElementPlusResolver(),VantResolver({
        importStyle: false,
      })], 
    }), 
    // 压缩插件  
    compression({  
      algorithm: 'gzip',  
      ext: '.gz',  
      threshold: 10240,  
      // minRatio: 0.8,  
      // deleteOriginalAssets: false, 
    }),  
  ],  
  resolve: {  
    alias: {  
      // '@ton-connect/ui-vue': resolve(__dirname, 'node_modules/@ton-connect/ui-vue/dist/index.js'),

    },  
  },  
  base: process.env.NODE_ENV === 'production' ? './' : '/',  
  build: {  
    outDir: 'dist',  
    terserOptions: {  
      compress: {  
        drop_console: true,  
        drop_debugger: true,  
      },  
    },  
    sourcemap: process.env.NODE_ENV !== 'production',  
    cssCodeSplit: true, // 启用 CSS 代码分割  
  },  

  server: {  
    https: {
      key: fs.readFileSync('C:\\Users\\谢商勇\\localhost.key'), 
      cert: fs.readFileSync('C:\\Users\\谢商勇\\localhost.crt') 
    },
    host: '192.168.0.19',
    proxy: {  
      '/api': {  
        target: 'http://localhost:5170',  
        changeOrigin: true, 
        // rewrite: (path) => path.replace(/^\/api/, ''), 
      },  
    },  
  }, 
  
  // 通过 `define` 选项来全局定义常量  
  define: {  
    'process.env': process.env,  
  },  

}); 